﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class TrinhDoNgoaiNguModels
    {
        public static List<TrinhDoNgoaiNgu> GetDSTDNgoaiNgu()
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSTrinhDoNgoaiNgu
                       // where dt.IDCanBo == id
                        select dt;
            return query.ToList<TrinhDoNgoaiNgu>();
        }
        public static List<TrinhDoNgoaiNgu> GetTrinhDoNNTheoCanBo(int id)
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSTrinhDoNgoaiNgu
                        where dt.IDCanBo == id
                        select dt;
            return query.ToList<TrinhDoNgoaiNgu>();
        }

        public static TrinhDoNgoaiNgu GetChiTietTrinhDoNgoaiNgu(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from s in context.DSTrinhDoNgoaiNgu
                         where s.ID == id
                         select s).FirstOrDefault();
            return query;

        }



        public static void Add(TrinhDoNgoaiNgu qhgd)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            context.DSTrinhDoNgoaiNgu.AddObject(qhgd);
            context.SaveChanges();
        }
        public static void Delete(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from h in context.DSTrinhDoNgoaiNgu
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSTrinhDoNgoaiNgu.DeleteObject(query);
            context.SaveChanges();

        }
        public static void DeleteAllOfPerson(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoNgoaiNgu
                        where h.IDCanBo == id
                        select h;
            foreach (var item in query)
            {
                context.DSTrinhDoNgoaiNgu.DeleteObject(item);
            }
            context.SaveChanges();
        }
        //sua dan toc
        public static void Update(TrinhDoNgoaiNgu id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoNgoaiNgu
                        where h.ID == id.ID
                        select h;
            TrinhDoNgoaiNgu kq = query.First<TrinhDoNgoaiNgu>();
            kq = id;
            context.DSTrinhDoNgoaiNgu.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
    }
}